#include "Genome.h"

#include <ctime>
#include <cmath>
#include <cstdlib>
#include "../Api-Blli/ApiBlli.h"

Genome::~Genome(void)
{
}

Genome::Genome(void)
{
}

int		Genome::MyRand(int a, int b)
{
	return rand() % (b - a) + a;
}

int		Genome::GetIndexRand(int servo)
{
	switch (servo)
	{
	case ApiBlli::Leg::FINGER:
		return (MyRand(GetIndexMin(servo), GetIndexMax(servo)));
		break;
	case ApiBlli::Leg::ARM:
		return (MyRand(GetIndexMin(servo), GetIndexMax(servo)));
		break;
	case ApiBlli::Leg::SHOULDER:
		return (MyRand(GetIndexMin(servo), GetIndexMax(servo)));
		break;
	default:
		return 0;
	}
}

int		Genome::GetIndexMin(int servo)
{
	switch (servo)
	{
	case ApiBlli::Leg::FINGER:
		return 0;
		break;
	case ApiBlli::Leg::ARM:
		return 0;
		break;
	case ApiBlli::Leg::SHOULDER:
		return 0;
		break;
	default:
		return 0;
	}
}

int		Genome::GetIndexMax(int servo)
{
	switch (servo)
	{
	case ApiBlli::Leg::FINGER:
		return 1024;
		break;
	case ApiBlli::Leg::ARM:
		return 1024;
		break;
	case ApiBlli::Leg::SHOULDER:
		return 1024;
		break;
	default:
		return 0;
	}
}

float	Genome::GetRadPerSecRand()
{
	return (float) MyRand(0, 1000);
}

/*
float	Genome::GetDegRandEpaule()
{
	int value = 0;

	if (rand() % 2)
	{
		// Si positif
		int max = 90;
		value = rand() % max;
	}
	else
	{
		// Si Negatif
		int max = 50;
		value = -(rand() % max);
	}
	return (float)(value);
}

float	Genome::GetDegRandBras()
{
	int value = 0;

	if (rand() % 2)
	{
		// Si positif
		int max = 65;
		value = rand() % max;
	}
	else
	{
		// Si Negatif
		int max = 140;
		value = -(rand() % max);
	}
	return (float)(value);
}

float	Genome::GetDegRandDoigt()
{
	int value = 0;

	if (rand() % 2)
	{
		// Si positif
		int max = 265;
		value = rand() % max;
	}
	else
	{
		// Si Negatif
		int max = 30;
		value = -(rand() % max);
	}
	return (float)(value);
}

//
//float	Genome::GetDegRand()
//{
//	int max = 90;
//	int a = rand() % max;
//	int b = rand() % 2;
//
//	return (float)(((b == 0 ? a : a * -1)));
//}

float	Genome::GetDegPerSecRand()
{
	int a = rand();
	int max = 306;
	int min = 0;

	int value = a % max;
	return (float)((value >= min) ? value : min);
}

int		Genome::GetGaitSizeRand()
{
	int max = 100;
	int min = 1;

	int value = rand() % max;
	return ((value >= min) ? value : min);
}

int		Genome::GetWaitNext()
{
	int max = 2000;
	int min = 0;

	int value = rand() % max;
	return ((value >= min) ? value : min);
}
*/